<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<head>
    <script src="../assets/js/echarts.min.js"></script>
    <script src="../assets/js/jquery.min.js"></script>
    <script src="../assets/js/theme.js"></script>
    <script src="../assets/js/amazeui.min.js"></script>
    <script src="../assets/js/amazeui.datatables.min.js"></script>
    <script src="../assets/js/dataTables.responsive.min.js"></script>
    <%--    <script src="../assets/js/app.js"></script>--%>
</head>

<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 图书类型列表
                <small>图书类型管理</small></div>
            <p class="page-header-description"></p>
        </div>
    </div>
</div>

<!-- 内容区域 -->
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">图书类型列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span
                                            class="am-icon-plus"></span> 新增图书类型
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black "
                               id="example-r">
                            <thead>
                            <tr>
                                <th>类型编号</th>
                                <th>类型名称</th>
                                <th>父类型</th>
                                <%--                                <th>时间</th>--%>
                                <%--                                <th>时间</th>--%>
                                <%--                                <th>时间</th>--%>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>


                            <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                <li class="am-disabled"><a href="#">«</a></li>
                                <li class="am-active"><a href="#">1</a></li>
                                <li><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li><a href="#">5</a></li>
                                <li><a href="#">»</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $.ajax({
        async: false,
        type: 'post',
        url: '<%=path%>/admin/GetTypeListServlet.do',
        success: function (result) {
            var jsonResult = $.parseJSON(result);
            //alert(jsonResult.state);
            if (jsonResult.state == 1000) {
                var type = jsonResult.data;
                //alert(type.length);
                var innerHtml = "";
                for (var i = 0; i < type.length; i++) {
                    innerHtml += " <tr class=\"gradeX\">\n" +
                        "                <td>" + type[i].id + "</td>\n" +
                        "                <td>" + type[i].name + "</td>\n" +
                        "                <td>" + type[i].parentId + "</td>\n" +
                        "                <td>\n" +
                        "                  <div class=\"tpl-table-black-operation\">\n" +
                        "                    <a id=\"type_update_href\">\n" +
                        "                      <i class=\"am-icon-pencil\"></i> 编辑\n" +
                        "                    </a>\n" +
                        "                    <a onclick=deleteType(\"" + type[i].id + "\") class=\"tpl-table-black-operation-del\">\n" +
                        "                      <i class=\"am-icon-trash\"></i> 删除\n" +
                        "                    </a>\n" +
                        "                  </div>\n" +
                        "                </td>\n" +
                        "              </tr>"
                }
                $("#example-r").children().eq(1).html(innerHtml);
            } else {
                alert("获取图书类型失败");
            }
        }
    });
    //修改图书类型
    $("#type_update_href").click(function () {
        $("#main_content").load("<%=path%>/admin/jsp/type-update2.jsp");
    });
    //删除图书类型
    function deleteType(id) {
        //alert(id);
        $.ajax({
            type: 'post',
            url: '<%=path%>/admin/AdminDeleteTypeServlet.do',
            data: {id:id},
            success: function (result) {
                var jsonResult = $.parseJSON(result);
                alert(jsonResult.state);
                if (jsonResult.state == 1000) {
                    alert("删除成功");
                    window.location.reload(true);
                } else {
                    alert("删除失败");
                }
            }
        })
    };

</script>





